package strongholdCraft.common.Items.tool;

import strongholdCraft.common.Items.Items;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.player.UseHoeEvent;

public class ItemChisel extends Item{
	public ItemChisel(int id){
		super(id);
		setUnlocalizedName("chisel");
		setMaxDamage(251);
		setMaxStackSize(1);
	}
	public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){

		if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack)){
			return false;
		}
		else{
			UseHoeEvent event = new UseHoeEvent(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6);
			if (MinecraftForge.EVENT_BUS.post(event)){
				return false;
				}
			
			if (event.getResult() == Result.ALLOW){
				par1ItemStack.damageItem(1, par2EntityPlayer);
				return true;
				}
			
			int var11 = par3World.getBlockId(par4, par5, par6);
			int var12 = par3World.getBlockId(par4, par5 + 1, par6);
			
			if ((par7 == 0 || var12 != 0 || var11 != Block.stone.blockID) && var11 != Block.stone.blockID){
				if ((par7 == 0 || var12 != 0 || var11 != Block.sandStone.blockID) && var11 != Block.sandStone.blockID){
					if ((par7 == 0 || var12 != 0 || var11 != Block.blockNetherQuartz.blockID) && var11 != Block.blockNetherQuartz.blockID){
						return false;								//here        									here
					}
					//TODO This needs to be changed from 'blockNetherQuartz' to whatever quartz is called in a future update.
					else{
						Block var13 = Block.blockNetherQuartz; // and here
						par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), var13.stepSound.getStepSound(), (var13.stepSound.getVolume() + 1.0F) / 2.0F, var13.stepSound.getPitch() * 0.8F);
						if (par3World.isRemote){
							return true;
						}
						else{		//"x,y,z,id,meta"
							par3World.setBlock(par4, par5, par6, var13.blockID, 1, 3);
							par1ItemStack.damageItem(1, par2EntityPlayer);
							return true;
						}
					}
				}
				else{
					Block var13 = Block.sandStone;
					par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), var13.stepSound.getStepSound(), (var13.stepSound.getVolume() + 1.0F) / 2.0F, var13.stepSound.getPitch() * 0.8F);
					if (par3World.isRemote){
						return true;
					}
					else{		//"x,y,z,id,meta"
						par3World.setBlock(par4, par5, par6, var13.blockID, 1, 3);
						par1ItemStack.damageItem(1, par2EntityPlayer);
						return true;
					}
				}
			}
			else{
				Block var13 = Block.stoneBrick;
				par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), var13.stepSound.getStepSound(), (var13.stepSound.getVolume() + 1.0F) / 2.0F, var13.stepSound.getPitch() * 0.8F);
				
				if (par3World.isRemote){
					return true;
				}
				else{		//"x,y,z,id,meta"
					par3World.setBlock(par4, par5, par6, var13.blockID, 3, 0x02);
					par1ItemStack.damageItem(1, par2EntityPlayer);
					return true;
					}
				}
		}
		
	}
	
	
	
}